home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / CAPABILI.{A7 < prev    next >
Text File  |  1999-09-17  |  10KB  |  335 lines

  1. /*
  2.  * This is <linux/capability.h>
  3.  *
  4.  * Andrew G. Morgan <morgan@transmeta.com>
  5.  * Alexander Kjeldaas <astor@guardian.no>
  6.  * with help from Aleph1, Roland Buresund and Andrew Main.
  7.  */ 
  8.  
  9. #ifndef _LINUX_CAPABILITY_H
  10. #define _LINUX_CAPABILITY_H
  11.  
  12. #include <linux/types.h>
  13. #include <linux/fs.h>
  14.  
  15. /* User-level do most of the mapping between kernel and user
  16.    capabilities based on the version tag given by the kernel. The
  17.    kernel might be somewhat backwards compatible, but don't bet on
  18.    it. */
  19.  
  20. /* XXX - Note, cap_t, is defined by POSIX to be an "opaque" pointer to
  21.    a set of three capability sets.  The transposition of 3*the
  22.    following structure to such a composite is better handled in a user
  23.    library since the draft standard requires the use of malloc/free
  24.    etc.. */
  25.  
  26. #define _LINUX_CAPABILITY_VERSION  0x19980330
  27.  
  28. typedef struct __user_cap_header_struct {
  29.     __u32 version;
  30.     int pid;
  31. } *cap_user_header_t;
  32.  
  33. typedef struct __user_cap_data_struct {
  34.         __u32 effective;
  35.         __u32 permitted;
  36.         __u32 inheritable;
  37. } *cap_user_data_t;
  38.   
  39. #ifdef __KERNEL__
  40.  
  41. /* #define STRICT_CAP_T_TYPECHECKS */
  42.  
  43. #ifdef STRICT_CAP_T_TYPECHECKS
  44.  
  45. typedef struct kernel_cap_struct {
  46.     __u32 cap;
  47. } kernel_cap_t;
  48.  
  49. #else
  50.  
  51. typedef __u32 kernel_cap_t;
  52.  
  53. #endif
  54.   
  55. #define _USER_CAP_HEADER_SIZE  (2*sizeof(__u32))
  56. #define _KERNEL_CAP_T_SIZE     (sizeof(kernel_cap_t))
  57.  
  58. #endif
  59.  
  60.  
  61. /**
  62.  ** POSIX-draft defined capabilities. 
  63.  **/
  64.  
  65. /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
  66.    overrides the restriction of changing file ownership and group
  67.    ownership. */
  68.  
  69. #define CAP_CHOWN            0
  70.  
  71. /* Override all DAC access, including ACL execute access if
  72.    [_POSIX_ACL] is defined. Excluding DAC access covered by
  73.    CAP_LINUX_IMMUTABLE. */
  74.  
  75. #define CAP_DAC_OVERRIDE     1
  76.  
  77. /* Overrides all DAC restrictions regarding read and search on files
  78.    and directories, including ACL restrictions if [_POSIX_ACL] is
  79.    defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */
  80.  
  81. #define CAP_DAC_READ_SEARCH  2
  82.     
  83. /* Overrides all restrictions about allowed operations on files, where
  84.    file owner ID must be equal to the user ID, except where CAP_FSETID
  85.    is applicable. It doesn't override MAC and DAC restrictions. */
  86.  
  87. #define CAP_FOWNER           3
  88.  
  89. /* Overrides the following restrictions that the effective user ID
  90.    shall match the file owner ID when setting the S_ISUID and S_ISGID
  91.    bits on that file; that the effective group ID (or one of the
  92.    supplementary group IDs shall match the file owner ID when setting
  93.    the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
  94.    cleared on successful return from chown(2). */
  95.  
  96. #define CAP_FSETID           4
  97.  
  98. /* Used to decide between falling back on the old suser() or fsuser(). */
  99.  
  100. #define CAP_FS_MASK          0x1f
  101.  
  102. /* Overrides the restriction that the real or effective user ID of a
  103.    process sending a signal must match the real or effective user ID
  104.    of the process receiving the signal. */
  105.  
  106. #define CAP_KILL             5
  107.  
  108. /* Allows setgid(2) manipulation */
  109. /* Allows setgroups(2) */
  110. /* Allows forged gids on socket credentials passing. */
  111.  
  112. #define CAP_SETGID           6
  113.  
  114. /* Allows set*uid(2) manipulation (including fsuid). */
  115. /* Allows forged pids on socket credentials passing. */
  116.  
  117. #define CAP_SETUID           7
  118.  
  119.  
  120. /**
  121.  ** Linux-specific capabilities
  122.  **/
  123.  
  124. /* Transfer any capability in your permitted set to any pid,
  125.    remove any capability in your permitted set from any pid */
  126.  
  127. #define CAP_SETPCAP          8
  128.  
  129. /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */
  130.  
  131. #define CAP_LINUX_IMMUTABLE  9
  132.  
  133. /* Allows binding to TCP/UDP sockets below 1024 */
  134.  
  135. #define CAP_NET_BIND_SERVICE 10
  136.  
  137. /* Allow broadcasting, listen to multicast */
  138.  
  139. #define CAP_NET_BROADCAST    11
  140.  
  141. /* Allow interface configuration */
  142. /* Allow administration of IP firewall, masquerading and accounting */
  143. /* Allow setting debug option on sockets */
  144. /* Allow modification of routing tables */
  145. /* Allow setting arbitrary process / process group ownership on
  146.    sockets */
  147. /* Allow binding to any address for transparent proxying */
  148. /* Allow setting TOS (type of service) */
  149. /* Allow setting promiscuous mode */
  150. /* Allow clearing driver statistics */
  151. /* Allow multicasting */
  152. /* Allow read/write of device-specific registers */
  153.  
  154. #define CAP_NET_ADMIN        12
  155.  
  156. /* Allow use of RAW sockets */
  157. /* Allow use of PACKET sockets */
  158.  
  159. #define CAP_NET_RAW          13
  160.  
  161. /* Allow locking of shared memory segments */
  162. /* Allow mlock and mlockall (which doesn't really have anything to do
  163.    with IPC) */
  164.  
  165. #define CAP_IPC_LOCK         14
  166.  
  167. /* Override IPC ownership checks */
  168.  
  169. #define CAP_IPC_OWNER        15
  170.  
  171. /* Insert and remove kernel modules */
  172.  
  173. #define CAP_SYS_MODULE       16
  174.  
  175. /* Allow ioperm/iopl access */
  176.  
  177. #define CAP_SYS_RAWIO        17
  178.  
  179. /* Allow use of chroot() */
  180.  
  181. #define CAP_SYS_CHROOT       18
  182.  
  183. /* Allow ptrace() of any process */
  184.  
  185. #define CAP_SYS_PTRACE       19
  186.  
  187. /* Allow configuration of process accounting */
  188.  
  189. #define CAP_SYS_PACCT        20
  190.  
  191. /* Allow configuration of the secure attention key */
  192. /* Allow administration of the random device */
  193. /* Allow device administration (mknod)*/
  194. /* Allow examination and configuration of disk quotas */
  195. /* Allow configuring the kernel's syslog (printk behaviour) */
  196. /* Allow sending a signal to any process */
  197. /* Allow setting the domainname */
  198. /* Allow setting the hostname */
  199. /* Allow calling bdflush() */
  200. /* Allow mount() and umount(), setting up new smb connection */
  201. /* Allow some autofs root ioctls */
  202. /* Allow nfsservctl */
  203. /* Allow VM86_REQUEST_IRQ */
  204. /* Allow to read/write pci config on alpha */
  205. /* Allow irix_prctl on mips (setstacksize) */
  206. /* Allow flushing all cache on m68k (sys_cacheflush) */
  207. /* Allow removing semaphores */
  208. /* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores
  209.    and shared memory */
  210. /* Allow locking/unlocking of shared memory segment */
  211. /* Allow turning swap on/off */
  212. /* Allow forged pids on socket credentials passing */
  213. /* Allow setting readahead and flushing buffers on block devices */
  214. /* Allow setting geometry in floppy driver */
  215. /* Allow turning DMA on/off in xd driver */
  216. /* Allow administration of md devices (mostly the above, but some
  217.    extra ioctls) */
  218. /* Allow tuning the ide driver */
  219. /* Allow access to the nvram device */
  220. /* Allow administration of apm_bios, serial and bttv (TV) device */
  221. /* Allow manufacturer commands in isdn CAPI support driver */
  222. /* Allow reading non-standardized portions of pci configuration space */
  223. /* Allow DDI debug ioctl on sbpcd driver */
  224. /* Allow setting up serial ports */
  225. /* Allow sending raw qic-117 commands */
  226. /* Allow enabling/disabling tagged queuing on SCSI controllers and sending
  227.    arbitrary SCSI commands */
  228. /* Allow setting encryption key on loopback filesystem */
  229.  
  230. #define CAP_SYS_ADMIN        21
  231.  
  232. /* Allow use of reboot() */
  233.  
  234. #define CAP_SYS_BOOT         22
  235.  
  236. /* Allow raising priority and setting priority on other (different
  237.    UID) processes */
  238. /* Allow use of FIFO and round-robin (realtime) scheduling on own
  239.    processes and setting the scheduling algorithm used by another
  240.    process. */
  241.  
  242. #define CAP_SYS_NICE         23
  243.  
  244. /* Override resource limits. Set resource limits. */
  245. /* Override quota limits. */
  246. /* Override reserved space on ext2 filesystem */
  247. /* NOTE: ext2 honors fsuid when checking for resource overrides, so 
  248.    you can override using fsuid too */
  249. /* Override size restrictions on IPC message queues */
  250. /* Allow more than 64hz interrupts from the real-time clock */
  251. /* Override max number of consoles on console allocation */
  252. /* Override max number of keymaps */
  253.  
  254. #define CAP_SYS_RESOURCE     24
  255.  
  256. /* Allow manipulation of system clock */
  257. /* Allow irix_stime on mips */
  258. /* Allow setting the real-time clock */
  259.  
  260. #define CAP_SYS_TIME         25
  261.  
  262. /* Allow configuration of tty devices */
  263. /* Allow vhangup() of tty */
  264.  
  265. #define CAP_SYS_TTY_CONFIG   26
  266.  
  267. #ifdef __KERNEL__
  268.  
  269. /*
  270.  * Internal kernel functions only
  271.  */
  272.  
  273. #ifdef STRICT_CAP_T_TYPECHECKS
  274.  
  275. #define to_cap_t(x) { x }
  276. #define cap_t(x) (x).cap
  277.  
  278. #else
  279.  
  280. #define to_cap_t(x) (x)
  281. #define cap_t(x) (x)
  282.  
  283. #endif
  284.  
  285. #define CAP_EMPTY_SET       to_cap_t(0)
  286. #define CAP_FULL_SET        to_cap_t(~0)
  287. #define CAP_INIT_EFF_SET    to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP))
  288. #define CAP_INIT_INH_SET    to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP))
  289.  
  290. #define CAP_TO_MASK(x) (1 << (x))
  291. #define cap_raise(c, flag)   (cap_t(c) |=  CAP_TO_MASK(flag))
  292. #define cap_lower(c, flag)   (cap_t(c) &= ~CAP_TO_MASK(flag))
  293. #define cap_raised(c, flag)  (cap_t(c) &   CAP_TO_MASK(flag))
  294.  
  295. static inline kernel_cap_t cap_combine(kernel_cap_t a, kernel_cap_t b)
  296. {
  297.      kernel_cap_t dest;
  298.      cap_t(dest) = cap_t(a) | cap_t(b);
  299.      return dest;
  300. }
  301.  
  302. static inline kernel_cap_t cap_intersect(kernel_cap_t a, kernel_cap_t b)
  303. {
  304.      kernel_cap_t dest;
  305.      cap_t(dest) = cap_t(a) & cap_t(b);
  306.      return dest;
  307. }
  308.  
  309. static inline kernel_cap_t cap_drop(kernel_cap_t a, kernel_cap_t drop)
  310. {
  311.      kernel_cap_t dest;
  312.      cap_t(dest) = cap_t(a) & ~cap_t(drop);
  313.      return dest;
  314. }
  315.  
  316. static inline kernel_cap_t cap_invert(kernel_cap_t c)
  317. {
  318.      kernel_cap_t dest;
  319.      cap_t(dest) = ~cap_t(c);
  320.      return dest;
  321. }
  322.  
  323. #define cap_isclear(c)       (!cap_t(c))
  324. #define cap_issubset(a,set)  (!(cap_t(a) & ~cap_t(set)))
  325.  
  326. #define cap_clear(c)         do { cap_t(c) =  0; } while(0)
  327. #define cap_set_full(c)      do { cap_t(c) = ~0; } while(0)
  328. #define cap_mask(c,mask)     do { cap_t(c) &= cap_t(mask); } while(0)
  329.  
  330. #define cap_is_fs_cap(c)     (CAP_TO_MASK(c) & CAP_FS_MASK)
  331.  
  332. #endif /* __KERNEL__ */
  333.  
  334. #endif /* !_LINUX_CAPABILITY_H */
  335.